<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/html">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>撞破南墙找西墙</title>
    <link href="https://cdn.staticfile.org/twitter-bootstrap/5.1.1/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" type="text/css" href="/static/s.css">
    <link rel="icon" href="{{ url_for('static', filename='favicon.ico') }}" type="image/x-icon">
</head>
<body style="background-color: #EFF2F6">

{% include '_nav_index.html' %}

<br>

<div class="container">
    <!--    <a href="/send">-->
    <!--        <button class="btn btn-major" style="width:100%; padding: 10px;">在表白墙上发布内容-->
    <!--        </button>-->
    <!--    </a><br><br>-->
    <div class="row">
        <div class="col-md-1"></div>
        <div class="col-md-6">

            <div class="contain_box" style="box-shadow: 1px 1px 5px gray;">
                <div class="left_avatar">
                    <img src="/static/headimg.jpg" width="60px" class="avatar me-3 rounded-circle">
                </div>
                <div class="right_div">
                    <form action="/send" , method="post" enctype="multipart/form-data">
                        <div class="mb-3 mt-3">
                            <textarea style="border: none; width: 98%; font-size: 17px; outline: none; resize: none;"
                                      placeholder="说点什么吧~" id="comment" name="content" rows="3"></textarea>
                            <br><br>
                            <div class="form-check mb-3">
                                <button type="submit" class="btn btn-primary btn-major">发布
                                </button>
                                <!--点击添加按钮只弹出模态框，不执行其它动作-->
                                <button type="button" class="btn btn_addimg" data-bs-toggle="modal"
                                        data-bs-target="#uploadImgModal">
                                    <img src="/static/icons/image.svg" width="20px">添加图片
                                </button>
                                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                <label class="form-check-label">
                                    <input class="form-check-input" type="checkbox" name="anonymous"> 匿名发送
                                </label>
                            </div>

                            <!-- 上传图片模态框 -->
                            <div class="modal fade" id="uploadImgModal" data-bs-keyboard="false" tabindex="-1"
                                 aria-labelledby="staticBackdropLabel" aria-hidden="true">
                                <div class="modal-dialog modal-dialog-centered">
                                    <div class="modal-content">
                                        <div class="modal-header">
                                            <h5 class="modal-title" id="updateImgModal-staticBackdropLabel">
                                                上传图片</h5>
                                            <button type="button" class="btn-close" data-bs-dismiss="modal"
                                                    aria-label="Close"></button>
                                        </div>
                                        <div class="modal-body">
                                            <div class="row mx-3">
                                                <!-- 图片类型：gif、png、jpeg -->
                                                <input type="file" id="img" name="img"
                                                       class="form-control mb-2"
                                                       accept="image/gif,image/png,image/jpeg"
                                                       placeholder="支持jpg、png、gif格式图片">
                                                <span class="text-secondary text-opacity-50">
                        支持jpg、png、gif格式图片
                    </span>
                                            </div>
                                        </div>
                                        <div class="modal-footer">
                                            <button type="button" class="btn btn-major" data-bs-dismiss="modal">确定
                                            </button>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>


                        <!--        <div class="input-group">-->
                        <!--            <label class="input-group-text">添加图片</label>-->
                        <!--            <input type="file" class="form-control" id="img" aria-describedby="inputGroupFileAddon04"-->
                        <!--                   aria-label="Upload" name="img">-->
                        <!--        </div>-->
                    </form>
                </div>
            </div>

            <br>
            {% for i in reslist %}
            <div class="contain_box" style="box-shadow: 1px 1px 5px gray;">
                <div class="left_avatar">
                    {% if i['type'] == 'anonymous' %}
                    <img src="/static/userheader.svg" width="60px" alt="User Avatar"
                         class="avatar me-3 rounded-circle">
                    {% else %}
                    <img src="{{ i['head'] }}" width="60px" alt="User Avatar"
                         class="avatar me-3 rounded-circle">
                    {% endif %}
                </div>
                <div class="right_div">
                    {% if i['type'] == 'anonymous' %}
                    <h5 class="mb-0">匿名用户</h5>
                    <p class="text-muted mb-0">{{ i['time'] }}</p>
                    {% else %}
                    <h5 class="mb-0">{{ i['name'] }}
                        {% if i['is_official'] %}&nbsp;<span class="badge bg-official">官方</span>{% endif %}
                        {% if i['is_vip'] %}&nbsp;<span class="badge bg-vip">VIP</span>{% endif %}
                    </h5>
                    <p class="text-muted mb-0">{{ i['time'] }}</p>
                    {% endif %}
                </div>
                <br>
                <div class="card-body">
                    <p class="post-content">{{ i['content']|safe }}</p>
                    {% if i['img'] %}
                    <a href="/uploads/{{ i['img'] }}" target="_blank">
                        <img src="/uploads/{{ i['img'] }}" class="img-fluid mt-3 img-style"></a>
                    {% endif %}
                    <br><br>
                    {% if i['is_self_liked'] %}
                    <button id="btn-approve-{{ i['mid'] }}" class="btn btn-approved"
                            onclick="approve({{ i['mid'] }}, {{ user['uid'] }})">已赞同 &nbsp; {{ i['likes']
                        }}
                    </button>
                    {% else %}
                    <button id="btn-approve-{{ i['mid'] }}" class="btn btn-disapproved"
                            onclick="approve({{ i['mid'] }}, {{ user['uid'] }})">赞同 &nbsp; {{ i['likes']
                        }}
                    </button>
                    {% endif %}
                    <a href="/messages?mid={{ i['mid'] }}">
                        <button type="submit" class="btn btn-ff9933">评论</button>
                    </a>
                </div>
            </div>
            {% endfor %}

            <!--            <div class="post" style="background-color: white; padding: 10px; box-shadow: 2px 2px 5px gray;">-->
            <!--                <br>-->
            <!--                <p>共{{ wall_total }}条内容</p>-->
            <!--                <hr>-->

            <!--                {% for i in reslist %}-->

            <!--                <div class="d-flex align-items-center">-->
            <!--                    {% if i['type'] == 'anonymous' %}-->
            <!--                    <img src="/static/userheader.svg" width="60px" alt="User Avatar"-->
            <!--                         class="avatar me-3 rounded-circle">-->
            <!--                    <div>-->
            <!--                        <h5 class="mb-0">匿名用户</h5>-->
            <!--                        <p class="text-muted mb-0">{{ i['time'] }}</p>-->
            <!--                    </div>-->
            <!--                    {% else %}-->
            <!--                    <img src="{{ i['head'] }}" width="60px" alt="User Avatar"-->
            <!--                         class="avatar me-3 rounded-circle">-->
            <!--                    <div>-->
            <!--                        <h5 class="mb-0">{{ i['name'] }}-->
            <!--                            {% if i['is_official'] %}&nbsp;<span class="badge bg-official">官方</span>{% endif %}-->
            <!--                            {% if i['is_vip'] %}&nbsp;<span class="badge bg-vip">VIP</span>{% endif %}-->
            <!--                        </h5>-->
            <!--                        <p class="text-muted mb-0">{{ i['time'] }}</p>-->
            <!--                    </div>-->
            <!--                    {% endif %}-->
            <!--                </div>-->
            <!--                <div class="card-body">-->
            <!--                    <p class="post-content">{{ i['content']|safe }}</p>-->
            <!--                    {% if i['img'] %}-->
            <!--                    <a href="/uploads/{{ i['img'] }}" target="_blank"><img src="/uploads/{{ i['img'] }}"-->
            <!--                                                                           width="200px" height="150px"-->
            <!--                                                                           class="img-fluid mt-3"></a>-->
            <!--                    {% endif %}-->
            <!--                    <br><br><a href="/messages?mid={{ i['mid'] }}">-->
            <!--                    <button type="submit" class="btn btn-ff9933">评论</button>-->
            <!--                </a>-->
            <!--                </div>-->

            <!--                <hr>-->
            <!--                {% endfor %}-->


            <br><br>
            <ul class="pagination justify-content-center">
                {% if page == 1 %}
                <li class="page-item disabled"><a class="page-link">首页</a></li>
                <li class="page-item disabled"><a class="page-link">上一页</a></li>
                {% else %}
                <li class="page-item"><a class="page-link" href="/wall">首页</a></li>
                <li class="page-item"><a class="page-link"
                                         href="/wall?page={{ page - 1 }}&start={{ prev_start }}">上一页</a></li>
                {% endif %}
                <li class="page-item active"><a class="page-link" href="#">{{ page }}</a></li>
                {% if page == page_num %}
                <li class="page-item disabled"><a class="page-link">下一页</a></li>
                {% else %}
                <li class="page-item"><a class="page-link" href="/wall?page={{ page + 1 }}&start={{ start }}">下一页</a>
                </li>
                {% endif %}
            </ul>

            <br><br><br><br><br>

        </div>

        <div class="col-md-4">
            {% include '_frame_right.html' %}
        </div>

        <div class="col-md-1"></div>
        <!--    <img class="card-img-bottom" src="https://static.runoob.com/images/mix/img_avatar.png" alt="Card image" style="width:100%">-->
    </div>
</div>


<script src="https://cdn.staticfile.org/twitter-bootstrap/5.1.1/js/bootstrap.bundle.min.js"></script>
<!--<script src="/static/bolang.json"></script>-->
<!--<script src="/static/yinghua.json"></script>-->

<script type="text/javascript">
    function approve(mid, uid) {
        if (uid == 0) {
            alert("您还未登录，请先登录");
        }
        else {
            let xhr= new XMLHttpRequest();
            xhr.open("GET", "/api/approve_message?mid=" + mid + "&uid=" + uid, true);
            xhr.send();

            xhr.onreadystatechange = function() {
                if (xhr.readyState == 4 && xhr.status == 200) {
                    var value = document.getElementById("btn-approve-" + mid).className;
                    if (value == "btn btn-approved") {
                        document.getElementById("btn-approve-" + mid).className = "btn btn-disapproved";
                        document.getElementById("btn-approve-" + mid).innerHTML = "赞同 &nbsp; " + xhr.response;
                    }
                    else {
                        document.getElementById("btn-approve-" + mid).className = "btn btn-approved";
                        document.getElementById("btn-approve-" + mid).innerHTML = "已赞同 &nbsp; " + xhr.response;
                    }
                }
                else if(xhr.status == 404) {

                }
            }
        }
    }
</script>

</body>
</html>